%%%-------------------------------------------------------------------
%%% @author kk
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%% 对数字列表中的奇数进行求和，后除以3的商得值为A，并将偶数求和后除以3的余数得值为B，然后求A+B结果，输出A、B、A+B
%%% @end
%%% Created : 19. 7月 2024 11:22
%%%-------------------------------------------------------------------
-module(d5).
-author("kk").

%% API
-export([sum/1, sumJi/2, start/0, getSumA_B/1]).

%% 列表偶数求和
sum([]) -> 0;
sum(List) -> sum(List, 0).
sum([], Count) -> Count;
sum([H | List], Sum) ->
  if
    H rem 2 == 0 -> Count = H + Sum, sum(List, Count);
    true -> sum(List, Sum)
  end.

%% 列表奇数求和
sumJi([]) -> 0;
sumJi(List) -> sumJi(List, 0).
sumJi([], Count) -> Count;
sumJi([H | List], Sum) ->
  if
    H rem 2 =/= 0 -> Count = H + Sum, sumJi(List, Count);
    true -> sumJi(List, Sum)
  end.

getSumA_B(List) ->
  A = sum(List),
  B = sumJi(List),
  AA = A / 3,
  BB = B rem 3,
  [A, B, AA + BB]. %% 返回值

start() ->
  List = [11, 2, 3, 4],
  Sum = sum(List),
  SumJi = sumJi(List),
  io:fwrite("oushu: ~w jishu: ~w", [Sum, SumJi]).